# 1. upper 大写  lower 小写
s1 = "Hello World!"
s2 = "Hello Python!"
print(s1)
s1UPPER = s1.upper() # 所有字母变成大写
print(s1UPPER)
print(s1.upper())
print(s2.lower()) # 所有字母变成小写

# 2. startswith 以xx开头 endswith 以xx结尾
s3 = " apple banana peach orange"
print("banana" in s3)
# 字符串是以什么内容开头
print(s3.startswith("apple"))
print(s3.startswith(" apple"))
print(s3.startswith(" ap"))
print(s3.startswith(" a"))
name = "张杰"
print(name.startswith("李"))
print(name.startswith("张"))
# 字符串内容是否以什么内容结尾
url1 = "http://www.baidu.com/aaa/bbb/ccc/a.png"
url2 = "http://www.baidu.com/aaa/bbb/ccc/a.jpg"
url3 = "http://www.baidu.com/aaa/bbb/ccc/a.mp3"
print(url1.endswith(".jpg"))
print(url2.endswith(".jpg"))
print(url3.endswith(".jpg"))

# 3. isdigit 判断是否是纯数字
numStr = input("请输入一个数字:")
# 先判断numStr是否是一个数字字符串
# print(numStr.isdigit())
if numStr.isdigit():
    # numStr是一个纯数字的代码
    num = int(numStr)
    print(num*2)
else:
    print('输入有误，请输入一个数字')

# 4. strip 去除字符串两端的空格或换行符
user = input('请输入用户名：')
user = user.strip()
print(user, len(user))


# 5. join 组合  split 分割
citys = "北京,哈尔滨,深圳,重庆,上海"
ret = citys.split(",") # 分割
print(ret)
print(len(ret))
ret2 = ";".join(ret) # 将列表里的内容拼接起来
print(ret2)


# 6. find 找不到，返回-1 index 找不到会报错
s = "yuan rain alvin eric"
ret = s.find("yuan")
print(ret)
ret = s.find("allen")
print(ret)
ret = s.index("rain")
print(ret)
ret = s.index("man")
print(ret)

# 7. count 计数
student_name = "张三 李四 王五 张三 张三 赵六"
print(student_name.count("张三"))

# 8. replace 替换,默认替换所有
info = "I am yuan"
print(info)
info = info.replace("yuan", "alex")
print(info)
